home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 12572 / 12572.xpi / content / rtc.js < prev    next >
Encoding:
JavaScript  |  2009-10-30  |  23.6 KB  |  571 lines

  1.  
  2.  
  3. //Well, this fights for your right to click - let's go for it ...
  4.  
  5.  
  6. var rtc = {
  7.         blinkTimer: 0,
  8.         delay: 1500,
  9.         prompts: Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService),
  10.  
  11.  
  12.         LOG: function(text)
  13.         {
  14.             var consoleService = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
  15.             consoleService.logStringMessage(String(text));
  16.         },
  17.  
  18.  
  19.         getPrefs: function()
  20.         {
  21.             var prefstr = navigator.preference("extensions.rtc.prefs");
  22.             if(!prefstr || prefstr.length < navigator.preference("extensions.rtc.prefsdefault").length) //possibly updated addon
  23.                 rtc.resetPrefs();
  24.  
  25.             var p = prefstr.split(",");
  26.             for(i = 0; i < p.length; i++){
  27.                 try{
  28.                     p[i] = parseInt(p[i]);
  29.                 }catch(e){alert("RTC, error loading preferences: " + e);} //rtc.resetPrefs();    break;
  30.             }
  31.             return p;
  32.         },
  33.  
  34.  
  35.         savePrefs: function(p)
  36.         {
  37.             var prefstr = p.join(",")
  38.             navigator.preference("extensions.rtc.prefs", prefstr);
  39.         },
  40.  
  41.  
  42.         resetPrefs: function()
  43.         {
  44.             navigator.preference("extensions.rtc.prefs", navigator.preference("extensions.rtc.prefsdefault")); 
  45.         },
  46.  
  47.  
  48.         optionsLoad: function()
  49.         {
  50.             var p = rtc.getPrefs();
  51.             for(i = 0; i < p.length; i++)
  52.             {
  53.                 if(el = document.getElementById(String(i)))
  54.                     el.checked = p[i];
  55.             } 
  56.         },
  57.  
  58.  
  59.         optionsSave: function()
  60.         {
  61.             var p = rtc.getPrefs();
  62.             for(i = 0; i < p.length; i++)
  63.             {
  64.                 if(el = document.getElementById(String(i)))
  65.                     p[i] = el.checked - 0;
  66.             }
  67.             rtc.savePrefs(p);
  68.         },
  69.  
  70.  
  71.         captureClick: function(event){
  72.             rightClick = false;
  73.             if(event.which && event.which == 3)
  74.                 rightClick = true;
  75.             else if (event.button && event.button == 2)
  76.                 rightClick = true;
  77.             if(!rightClick)//left click
  78.             {
  79.                 rtc.buttonrun();
  80.                 return;
  81.             }
  82.             //right click...
  83.         },
  84.  
  85.  
  86.         openConfigWindow: function()
  87.         {
  88.             window.openDialog('chrome://rtc/content/rtcoptions.xul', '_blank', 'chrome=yes,modal=yes,resizable=no,centerscreen=yes');
  89.         },
  90.  
  91.  
  92.         populateSBContext: function()
  93.         {
  94.                 var mPopup = document.getElementById("rtc-statusbarcontextmenu"); 
  95.                 if(!mPopup) 
  96.                     return;
  97.                 while (mPopup.hasChildNodes()) {
  98.                   mPopup.removeChild(mPopup.firstChild);
  99.                 }
  100.                 //add items
  101.                 var mi = mPopup.appendChild(document.createElement("menuitem")); 
  102.                 mi.setAttribute("oncommand", "rtc.openConfigWindow()");
  103.                 mi.setAttribute("label", "Options");
  104.         },
  105.  
  106.  
  107.         buttonrun: function(){
  108.             var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
  109.             if(wm && wm.getMostRecentWindow("navigator:browser") && wm.getMostRecentWindow("navigator:browser").content)
  110.                 rtc.run(wm.getMostRecentWindow("navigator:browser").content.document, true);
  111.         },
  112.  
  113.  
  114.  
  115.         parse: function(clicked, imgArr, topwin){ //frames and iframes
  116.             rtc.enable(topwin.document, clicked, imgArr);
  117.             for (var i=0; i < topwin.frames.length; i++)
  118.                 rtc.parse(clicked, imgArr, topwin.frames[i]);
  119.         },
  120.  
  121.  
  122.  
  123.         run: function(doc, clicked){
  124.             navigator.preference("dom.event.contextmenu.enabled", false);
  125.             navigator.preference("nglayout.events.dispatchLeftClickOnly", true);//not work currently due to Firefox bug
  126.             if(!doc instanceof HTMLDocument || !doc.location || !doc.getElementsByTagName('head')[0])
  127.                 return;
  128.  
  129.             doc.imgs = [];
  130.  
  131.  
  132.             var topwin = doc.defaultView.top; 
  133.             rtc.parse(clicked, doc.imgs, topwin); //parse frames and execute RTC (enable, collect images, ...)
  134.  
  135.             var p = rtc.getPrefs();
  136.             if(p[26])
  137.             {
  138.  
  139.                 doc.documentElement.innerHTML = ""; //build empty document 
  140.                 var head = doc.createElement('head');
  141.                 doc.documentElement.appendChild(head);
  142.                 var elem = doc.createElement('title')
  143.                 head.appendChild(elem);
  144.                 elem.textContent = "RightToClick Image View";
  145.                 doc.documentElement.appendChild(doc.createElement('body'));
  146.  
  147.                 elem = doc.createElement('div');
  148.                 doc.body.appendChild(elem);
  149.                 elem.style.setProperty("max-width", (window.innerWidth - 10) + "px", "important"); 
  150.                 elem.style.setProperty("max-height", (window.innerHeight - 150) + "px", "important"); 
  151.                 elem.style.setProperty("overflow", "auto", "important");
  152.  
  153.                 var known = "";;
  154.                 for (i = 0; i < doc.imgs.length; i++) //add collected  images
  155.                 {
  156.                     if(known.indexOf(doc.imgs[i]) != -1) //prevent duplicates
  157.                         continue;
  158.                     known += doc.imgs[i];
  159.                     var newimg = doc.createElement('img');
  160.                     newimg.src = String(doc.imgs[i]); 
  161.                     elem.appendChild(newimg); //also recreate background images as normal images
  162.                     newimg.style.setProperty("max-width", "350px", "important"); 
  163.                     newimg.style.setProperty("max-height", "350px", "important"); 
  164.                 }
  165.  
  166.                 doc.defaultView.scrollbars.visible = true;
  167.                 window.scrollbars.visible = true;
  168.                 doc.defaultView.scrollbars.hidden = false;
  169.                 window.scrollbars.hidden = false;
  170.             }
  171.             doc.imgs = null;
  172.         },
  173.  
  174.  
  175.         isEventListenerMatch: function(p,t){
  176.  
  177.             if( (p[0] && (t=="focus")) ||
  178.                 (p[1] && (t=="selectstart" || t=="copy" || t=="paste" || t=="cut")) ||
  179.                 (p[4] && (t=="contextmenu")) ||
  180.                 (p[2] && (t=="dragstart" || t=="drag" || t=="dragover")) ||
  181.                 (p[3] && (t=="mouseup" || t=="mousedown" || t=="click")) ||
  182.                 (p[5] && (t=="mouseover" || t=="mouseout" || t=="mousemove")) ||
  183.                 (p[6] && (t=="dblclick")) ||
  184.                 (p[7] && (t=="keydown" || t=="keyup" || t=="keypress"))
  185.             ) return true;
  186.             return false;
  187.         },
  188.  
  189.  
  190.         getFuncName: function(stringValue){
  191.             var funcNamePattern = /function\s*([^\(]*)/mi;
  192.             var funcName = funcNamePattern.exec(stringValue);
  193.             if (funcName && funcName[1])
  194.                 return funcName[1];
  195.             return null;
  196.         },
  197.  
  198.  
  199.         enable: function(doc, clicked, imgArr){
  200.                 var elem, i;
  201.                 var win = doc.defaultView;
  202.                 var p = rtc.getPrefs();
  203.                 var killEventListeners = " ";
  204.                 var removeIDs = " ";
  205.  
  206.                 //rtc.LOG("Parsing " + doc.location.href);
  207.  
  208.                 //part 1: Disarm eventlisteners
  209.                 try{
  210.                     if(p[24]){
  211.                         var eventListenerService; //Disable site's non-anonymous eventListeners
  212.                         try{
  213.                              eventListenerService = Components.classes["@mozilla.org/eventlistenerservice;1"].getService(Components.interfaces.nsIEventListenerService);
  214.                         }catch(e){}
  215.                         if(eventListenerService) //FF version 3.7 minimum needed
  216.                         {
  217.                              var allElements = doc.getElementsByTagName('*');
  218.                              for (i = 0; i < allElements.length; i++) //all element listeners
  219.                              {
  220.                                 var elsi = eventListenerService.getListenerInfoFor(allElements[i]);
  221.                                 for (z = 0; z < elsi.length; z++)
  222.                                 {
  223.                                     if(rtc.isEventListenerMatch(p, elsi[z].type)) 
  224.                                     {
  225.                                         if (funcName = rtc.getFuncName(elsi[z].stringValue))
  226.                                         {
  227.                                             if (!allElements[i].id || doc.getElementById(allElements[i].id) != allElements[i])
  228.                                             {
  229.                                                 allElements[i].id = "rtc-ceid" + Math.random();
  230.                                                 var eventobject = "document.getElementById('" + allElements[i].id + "')";
  231.                                                 removeIDs += eventobject + ".removeAttribute('id'); ";
  232.                                             }else
  233.                                                 var eventobject = "document.getElementById('" + allElements[i].id + "')";
  234.                                             killEventListeners += eventobject + ".removeEventListener('" + elsi[z].type + "', " + funcName + "," + elsi[z].capturing + "); ";
  235.                                         }
  236.                                     }
  237.                                 }
  238.                              }
  239.                             var elsi = eventListenerService.getListenerInfoFor(doc); //object document listeners
  240.                             for (z = 0; z < elsi.length; z++)
  241.                             {
  242.                                 if(rtc.isEventListenerMatch(p, elsi[z].type)) 
  243.                                 {
  244.                                     if (funcName = rtc.getFuncName(elsi[z].stringValue))
  245.                                         killEventListeners += "document.removeEventListener('" + elsi[z].type + "', " + funcName + "," + elsi[z].capturing + "); ";
  246.                                 }
  247.                             }
  248.                             var elsi = eventListenerService.getListenerInfoFor(win); //object window listeners
  249.                             for (z = 0; z < elsi.length; z++)
  250.                             {
  251.                                 if(rtc.isEventListenerMatch(p, elsi[z].type)) 
  252.                                 {
  253.                                     if (funcName = rtc.getFuncName(elsi[z].stringValue))
  254.                                         killEventListeners += "window.removeEventListener('" + elsi[z].type + "', " + funcName + "," + elsi[z].capturing + "); ";
  255.                                 }
  256.                             }
  257.                              killEventListeners += removeIDs;
  258.                         }
  259.  
  260.                         //Firefox without ELS support
  261.                         doc.body = doc.body.cloneNode(true);    //remove all body eventlisteners
  262.                         doc.addEventListener('click', function (event) {var cm = document.getElementById("contentAreaContextMenu"); 
  263.                             if(event.button == 2)   cm.openPopupAtScreen(event.screenX, event.screenY, false); 
  264.                             else if(event.target.href || event.target.src) doc.location = event.target.href ? event.target.href:event.target.src;}
  265.                         , true);
  266.                     }
  267.                 }catch(e){rtc.LOG("RTC exception-1: " + e);}
  268.  
  269.  
  270.  
  271.                 //part 2: Disable site's event attributes (needs to be injected in HTML <head> for this) and remove onEvent-attributes
  272.                 try{
  273.                      var head_tag = doc.getElementsByTagName('head')[0];  
  274.                      var script_tag = doc.createElement('script');  
  275.                      script_tag.setAttribute('type', 'text/javascript');  
  276.                      script_tag.setAttribute('id', 'buttonscr'); 
  277.                      var text ="function rtcenable(){var P=[" + p + "]; try{if(P[0]) document.body.onfocus = null; if(P[1]) document.body.oncopy= null; if(P[1]) document.body.onselectstart = null;if(P[2]) document.body.ondragover = null; if(P[2]) document.body.ondrag = null; if(P[2]) document.body.ondragstart = null;if(P[3]) document.body.onmouseup = null;if(P[3]) document.body.onmousedown = null;if(P[3]) document.body.onclick = null;if(P[4]) document.body.oncontextmenu = null;if(P[5]) document.body.onmouseover = null;if(P[5]) document.body.onmouseout = null;if(P[5]) document.body.onmousemove = null;if(P[6]) document.body.ondblclick = null;if(P[7]) document.body.onkeydown = null;if(P[7]) document.body.onkeyup = null;if(P[7]) document.body.onkeypress = null;if(P[0]) document.onfocus = null;if(P[1]) document.oncopy = null;if(P[1]) document.onselectstart = null;if(P[2]) document.ondragover = null;if(P[2]) document.ondrag = null;if(P[2]) document.ondragstart = null;if(P[3]) document.onmouseup = null; if(P[3]){ document.onmousedown = null;}if(P[3]) document.onclick = null;if(P[4]) document.oncontextmenu = null;if(P[5]) document.onmouseover = null;if(P[5]) document.onmouseout = null;if(P[5]) document.onmousemove = null;if(P[6]) document.ondblclick = null;if(P[7]) document.onkeydown = null;if(P[7]) document.onkeyup = null;if(P[7]) document.onkeypress = null;if(P[0]) window.onfocus = null;if(P[1]) window.oncopy = null;if(P[1]) window.onselectstart = null;if(P[2]) window.ondragover = null;if(P[2]) window.ondrag = null;if(P[2]) window.ondragstart = null;if(P[3]) window.onmouseup = null; if(P[3]){ window.onmousedown = null;}if(P[3]) window.onclick = null;if(P[4]) window.oncontextmenu = null;if(P[5]) window.onmouseover = null;if(P[5]) window.onmouseout = null;if(P[5]) window.onmousemove = null;if(P[6]) window.ondblclick = null;if(P[7]) window.onkeydown = null;if(P[7]) window.onkeyup = null;if(P[7]) window.onkeypress = null;}catch(e){}";
  278.                      text += " var elements = document.getElementsByTagName('*'); for (i = 0; i < elements.length; i++){var el = elements[i]; "; 
  279.  
  280.                      text += " if(P[0] && el.hasAttribute('onfocus')) try{el.removeAttribute('onFocus');}catch(e){} "; 
  281.                      text += " if(P[0]) try{el.onfocus=null;}catch(e){} "; 
  282.                      text += " if(P[0]) try{el.style.setProperty('-moz-user-focus', 'normal', 'important');}catch(e){} "; 
  283.                      text += " if(P[0]) try{el.style.setProperty('-moz-user-input', 'enabled', 'important');}catch(e){} "; 
  284.  
  285.                      text += " if(P[1] && el.hasAttribute('onselectstart')) try{el.removeAttribute('onselectstart');}catch(e){} "; 
  286.                      text += " if(P[1] && el.hasAttribute('oncopy')) try{el.removeAttribute('oncopy');}catch(e){} "; 
  287.                      text += " if(P[1] && el.hasAttribute('onpaste')) try{el.removeAttribute('onpaste');}catch(e){} "; 
  288.                      text += " if(P[1] && el.hasAttribute('oncut')) try{el.removeAttribute('oncut');}catch(e){} "; 
  289.                      text += " if(P[1]) try{el.style.setProperty('-moz-user-select', 'text', 'important');}catch(e){} "; 
  290.                      text += " if(P[1]) try{el.style.setProperty('cursor', '', '');}catch(e){} "; 
  291.                      text += " if(P[1]) try{el.oncopy=null;}catch(e){} ";
  292.                      text += " if(P[1]) try{el.onpaste=null;}catch(e){} ";
  293.                      text += " if(P[1]) try{el.oncut=null;}catch(e){} ";
  294.                      text += " if(P[1]) try{el.onselectstart=null;}catch(e){} ";
  295.  
  296.                      text += " if(P[4] && el.hasAttribute('oncontextmenu')) try{el.removeAttribute('oncontextmenu');}catch(e){} "; 
  297.                      text += " if(P[4]) try{el.oncontextmenu=null;}catch(e){} ";
  298.  
  299.                      text += " if(P[2] && el.hasAttribute('ondragover')) try{el.removeAttribute('ondragover');}catch(e){} ";
  300.                      text += " if(P[2] && el.hasAttribute('ondrag')) try{el.removeAttribute('ondrag');}catch(e){} ";
  301.                      text += " if(P[2] && el.hasAttribute('ondragstart')) try{el.removeAttribute('ondragstart');}catch(e){} "; 
  302.                      text += " if(P[2]) try{el.ondragover=null;}catch(e){} ";
  303.                      text += " if(P[2]) try{el.ondrag=null;}catch(e){} ";
  304.                      text += " if(P[2]) try{el.ondragstart=null;}catch(e){} ";
  305.  
  306.  
  307.                      text += " if(P[3] && el.hasAttribute('onmouseup')) try{el.removeAttribute('onmouseup');}catch(e){} "; 
  308.                      text += " if(P[3] && el.hasAttribute('onmousedown')) try{el.removeAttribute('onmousedown');}catch(e){} "; 
  309.                      text += " if(P[3] && el.hasAttribute('onclick')) try{el.removeAttribute('onclick');}catch(e){} "; 
  310.                      text += " if(P[3]) try{el.onmouseup=null;}catch(e){} ";
  311.                      text += " if(P[3]) try{el.onmousedown=null;}catch(e){} ";
  312.                      text += " if(P[3]) try{el.onclick=null;}catch(e){} ";
  313.  
  314.                      text += " if(P[5] && el.hasAttribute('onmouseover')) try{el.removeAttribute('onmouseover');}catch(e){} "; 
  315.                      text += " if(P[5] && el.hasAttribute('onmouseout')) try{el.removeAttribute('onmouseout');}catch(e){} "; 
  316.                      text += " if(P[5] && el.hasAttribute('onmousemove')) try{el.removeAttribute('onmousemove');}catch(e){} "; 
  317.                      text += " if(P[5]) try{el.onmouseover=null;}catch(e){} ";
  318.                      text += " if(P[5]) try{el.onmouseout=null;}catch(e){} ";
  319.                      text += " if(P[5]) try{el.onmousemove=null;}catch(e){} ";
  320.  
  321.                      text += " if(P[6] && el.hasAttribute('ondblclick')) try{el.removeAttribute('ondblclick');}catch(e){} "; 
  322.                      text += " if(P[6]) try{el.ondblclick=null;}catch(e){} ";
  323.  
  324.                      text += " if(P[7] && el.hasAttribute('onkeydown')) try{el.removeAttribute('onkeydown');}catch(e){} "; 
  325.                      text += " if(P[7] && el.hasAttribute('onkeyup')) try{el.removeAttribute('onkeyup');}catch(e){} "; 
  326.                      text += " if(P[7] && el.hasAttribute('onkeypress')) try{el.removeAttribute('onkeypress');}catch(e){} "; 
  327.                      text += " if(P[7]) try{el.onkeydown=null;}catch(e){}"; 
  328.                      text += " if(P[7]) try{el.onkeyup=null;}catch(e){}"; 
  329.                      text += " if(P[7]) try{el.onkeypress=null;}catch(e){}"; 
  330.  
  331.                      text += " if(P[8] && el.hasAttribute('disabled')) try{el.removeAttribute('disabled');}catch(e){} "; 
  332.                      text += " if(P[8] && el.hasAttribute('readonly')) try{el.removeAttribute('readonly');}catch(e){} ";
  333.                      text += " if(P[8]) try{el.style.setProperty('-moz-user-modify', 'read-write', 'important');}catch(e){} ";  
  334.                      text += " if(P[8]) try{el.disabled=false;}catch(e){}"; 
  335.                      text += " if(P[8]) try{el.readonly=false;}catch(e){}"; 
  336.  
  337.                      text += " }";
  338.  
  339.                      //Disarm  document and window eventlisteners
  340.                      if(p[24]){
  341.                          text += " if(!document.docevents) document.docevents = []; for(var i= 0; i < document.docevents.length; i++) document.removeEventListener(document.docevents[i][0], document.docevents[i][1], document.docevents[i][2]); ";
  342.                          text += " if(!document.winevents) document.winevents = []; for(var i= 0; i < document.winevents.length; i++) document.removeEventListener(document.winevents[i][0], document.winevents[i][1], document.winevents[i][2]); ";
  343.                      }
  344.                      text += " var rtcexecuted = document.createElement('div');rtcexecuted.id = 'rtc-executed';document.body.appendChild(rtcexecuted);  } document.addEventListener('load', function(){setTimeout(rtcenable," + rtc.delay + ");},true); rtcenable(); "; 
  345.                      text += " var buttonscript = document.getElementById('buttonscr'); buttonscript.parentNode.removeChild(buttonscript); ";
  346.  
  347.  
  348.                      text += killEventListeners; 
  349.                      script_tag.text = text;
  350.                      head_tag.appendChild(script_tag);  
  351.                 }catch(e){rtc.LOG("RTC exception-2: " + e);}
  352.  
  353.  
  354.                 //part 3: Disarm or disable potentially evil functions
  355.                 try{
  356.                     if(typeof win.wrappedJSObject != "undefined")
  357.                     {
  358.                         if(p[20])
  359.                             win.wrappedJSObject.setTimeout = function () 
  360.                             {
  361.                                 win.wrappedJSObject.setTimeout = function() {};
  362.                                 return null;
  363.                             }
  364.                         if(p[20])
  365.                             win.wrappedJSObject.setInterval = function () 
  366.                             {
  367.                                 win.wrappedJSObject.setInterval = function() {};
  368.                                 return null;
  369.                             }
  370.                         if(p[21])
  371.                             win.wrappedJSObject.showModalDialog = function () 
  372.                             {
  373.                                 win.wrappedJSObject.showModalDialog = function() {};
  374.                                 return null;
  375.                             }
  376.                     }
  377.                 }catch(e){rtc.LOG("RTC  exception-3: " + e);}
  378.  
  379.  
  380.  
  381.                 if(p[25] && !p[26])
  382.                     rtc.setStylesDisabled(true, doc); //disable CSS styles
  383.  
  384.  
  385.                 //extract images
  386.                 if(p[26])
  387.                 {
  388.                     var allElements = doc.getElementsByTagName('*'); //search background images
  389.                     for (i = 0; i < allElements.length; i++) 
  390.                     {
  391.                         if(ComputedStyle = allElements[i].ownerDocument.defaultView.getComputedStyle(allElements[i], ""))
  392.                         {
  393.                             if(url = String(ComputedStyle.getPropertyValue("background-image")))
  394.                             {
  395.                                 if(url  != "none")
  396.                                 {
  397.                                     url = String(url.replace(/^url\(/, "").replace(/\)$/, ""));
  398.                                     imgArr.push(url);
  399.                                 }
  400.                             }
  401.                         }
  402.                         if(allElements[i].tagName === "IMG") //foreground images
  403.                         {
  404.                             if(url = allElements[i].src)
  405.                                 imgArr.push(url);
  406.                         }
  407.                     }
  408.                 }
  409.  
  410.                 //rtc.LOG("RTC all actions done");
  411.                 clearTimeout(rtc.blinkTimer);
  412.                 rtc.blinkIcon((clicked === true) ? 0 : 12, doc, null);
  413.         },
  414.  
  415.  
  416.  
  417.         setStylesDisabled: function(disabled, doc){
  418.             if(gBrowser && gBrowser.markupDocumentViewer){
  419.                 gBrowser.markupDocumentViewer.authorStyleDisabled = disabled;
  420.                 doc.stylesDisabled = disabled;
  421.             }
  422.         },
  423.  
  424.  
  425.         blinkIcon: function(num, doc, executed){
  426.             if(executed)
  427.             {
  428.                 var img = document.getElementById('rtc-statusbarimg');
  429.                 if(num % 2 == 0){
  430.                     img.setAttribute('src', 'chrome://rtc/skin/rtc.png');  //even number
  431.                     if(num > 11)
  432.                         return; 
  433.                 }else
  434.                     img.setAttribute('src', 'chrome://rtc/skin/rtcd.png');
  435.                 num++;
  436.             }else if(executed = doc.getElementById('rtc-executed')){
  437.                 executed.parentNode.removeChild(executed);
  438.             }
  439.             rtc.blinkTimer = setTimeout(rtc.blinkIcon, 400, num, doc, executed);
  440.         },
  441.  
  442.  
  443.         nullPrompts: function (checked, win, event) {
  444.             if (checked){ 
  445.                 event.preventDefault();
  446.                 event.stopPropagation();
  447.                 win.wrappedJSObject.alert = function() {};
  448.                 win.wrappedJSObject.confirm = function() {};
  449.                 win.wrappedJSObject.prompt = function() {};
  450.             }
  451.         },
  452.  
  453.  
  454.         onContentLoaded: function (event) {
  455.                 var head_tag = event.target.getElementsByTagName('head')[0];
  456.                 if(!head_tag)
  457.                     return;  
  458.                 var script_tag = event.target.createElement('script');  
  459.                 script_tag.setAttribute('type', 'text/javascript');  
  460.                 script_tag.setAttribute('id', 'domscr'); 
  461.                 var text = "document.docevents = []; var oldDAEL = document.addEventListener; document.addEventListener = function (oldDAEL) {return function (evt, func, bCapture) {oldDAEL.call (this, evt, func, bCapture); document.docevents.push( [evt, func, bCapture] ); } }(oldDAEL); ";
  462.                 text += "  document.winevents = []; var oldWAEL = window.addEventListener; window.addEventListener = function (oldWAEL) {return function (evt, func, bCapture) {oldWAEL.call (this, evt, func, bCapture); document.winevents.push( [evt, func, bCapture] ); } }(oldWAEL); "; 
  463.                 text += " var domscript = document.getElementById('domscr'); domscript.parentNode.removeChild(domscript); ";
  464.                 script_tag.text = text;
  465.                 head_tag.appendChild(script_tag);  
  466.         },
  467.     
  468.  
  469.  
  470.         onShow: function (event) {
  471.             if(!rtc.getPrefs()[23])
  472.                 return;
  473.             setTimeout(rtc.run, 250, event.target);
  474.         },
  475.  
  476.  
  477.  
  478.         onDialog: function (event) { 
  479.             rtc.wrapPrompts(event.target.document, event.target.document.defaultView, event);
  480.         },
  481.  
  482.  
  483.  
  484.         onBeforeUnLoading: function (event) { 
  485.             if(event.originalTarget.stylesDisabled)
  486.                 rtc.setStylesDisabled(false, event.originalTarget);
  487.         },
  488.  
  489.  
  490.  
  491.         //part 4: Disarm prompts (add a checkbox)
  492.         wrapPrompts: function (doc, win, event) 
  493.         {
  494.             if(typeof win.wrappedJSObject == "undefined")
  495.                 return;
  496.             var p = rtc.getPrefs();
  497.             if(!p[22] || win.RTCdone || typeof win.wrappedJSObject == "undefined")
  498.                 return;
  499.  
  500.             var domain;
  501.             try{
  502.                 domain = doc.domain;
  503.             }catch(e){}
  504.             var titlemsg = domain ? ("The page at " + doc.domain + " says: ") : "Javascript Application";
  505.  
  506.             var checkmsg = "Stop dialog popups on this page";
  507.             var check = {value: false};   
  508.  
  509.             win.wrappedJSObject.alert = function (message) 
  510.             {
  511.                 rtc.prompts.alertCheck(win, titlemsg, String(message), checkmsg, check);
  512.                 rtc.nullPrompts(check.value, win, event);
  513.             }
  514.             win.wrappedJSObject.confirm = function (message) 
  515.             {
  516.                 var val = rtc.prompts.confirmCheck(win, titlemsg, String(message), checkmsg, check);
  517.                 rtc.nullPrompts(check.value, win, event);
  518.                 return val;
  519.             }
  520.             win.wrappedJSObject.prompt = function (message, val) 
  521.             {
  522.                 var input = {value: String(val)}; 
  523.                 var val = rtc.prompts.prompt(win, titlemsg, String(message), input, checkmsg, check);
  524.                 rtc.nullPrompts(check.value, win, event);
  525.                 if(val)
  526.                     return input.value;
  527.                 return null;
  528.             }
  529.             win.RTCdone = true;
  530.         },
  531.  
  532.  
  533.  
  534.         DisableCSSToggled: function (event) { 
  535.             if(document.getElementById(event.target.id).checked  && !navigator.preference("extensions.rtc.noWarningDisableCSS"))
  536.             {
  537.                 check = {value: false}; 
  538.                 if(!rtc.prompts.confirmCheck(null, "RightToClick", "Disabling CSS usually makes pages look strange but might help to save images.\r\n\r\nStill disable CSS?", "Do not show this again", check))
  539.                     document.getElementById(event.target.id).checked = false;
  540.                 navigator.preference("extensions.rtc.noWarningDisableCSS", check.value);
  541.             }
  542.         },
  543.  
  544.  
  545.         FetchImagesToggled: function () { 
  546.             if(document.getElementById("26").checked)
  547.                 document.getElementById("25").disabled = true;
  548.             else
  549.                 document.getElementById("25").disabled = false;
  550.         },
  551.  
  552.  
  553.  
  554.  
  555.         pageInfo: function () { 
  556.             var doc = null;
  557.             var initialTab = "mediaTab";
  558.             var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
  559.             if(wm && wm.getMostRecentWindow("navigator:browser") && wm.getMostRecentWindow("navigator:browser").content)
  560.                 doc = wm.getMostRecentWindow("navigator:browser").content.document;
  561.             var args = {doc: doc, initialTab: "securityTab"};
  562.             window.openDialog('chrome://browser/content/pageinfo/pageInfo.xul', '_blank', 'chrome,toolbar,dialog=no,resizable', args);
  563.         },
  564.  
  565. };
  566.  
  567.  
  568.         document.addEventListener("DOMContentLoaded", rtc.onContentLoaded, true);
  569.         document.addEventListener("pageshow", rtc.onShow, true);
  570.         document.addEventListener("stop", rtc.onShow, true);
  571.         document.addEventListener("beforeunload", rtc.onBeforeUnLoading, true);